/**
 * Written by Timbot
 * V1.0, June 2007
 */
package com.as3.timbot.data.collections
{
	import com.as3.timbot.data.iterators.IIterator;
	import com.as3.timbot.data.collections.IIterable;
	import com.as3.timbot.data.iterators.ArrayIterator;
	import com.as3.timbot.data.iterators.ArrayReverseIterator;
	/**
	* Makes Collections iterable via an Iterator
	*/
	public class DynamicQueue implements IIterable
	{
		private var __data:Array;
		
		public function DynamicQueue()
		{
			clear();
		}
		/**
		* Clears the queue entirely
		* @return void.
		*/
		public function clear():void
		{
			__data = new Array();
		}
		/**
		* Adds an element to the end of the queue
		* @return void.
		*/
		public function enqueue(o:Object):void
		{
			__data.push(o);
		}
		/**
		* Removes an element from the beginning of the queue
		* Returns the removed element
		* @return Object
		*/
		public function dequeue(): Object
		{
			return __data.shift();
		}
		/**
		* Returns if the queue has elements enqueued.
		* @return Boolean.
		*/
		public function isEmpty(): Boolean
		{
			return __data.length == 0;
		}
		/**
		* Returns the first element in the queue
		* @return Object.
		*/
		public function peek() : Object
		{
			return __data[0];
		}
		/**
		* Returns all the elements of the queue
		* @return Array.
		*/
		public function getElements() : Array
		{
			return __data.concat();
		}
		/**
		* Returns length of the queue
		* @return Number.
		*/
		public function getLength(): Number
		{
			return __data.length;
		}
		/**
		* Returns the iterator for the queue, can be a 
		* forward or reverse iterator
		* @return IIterator
		*/
		public function iterator(type:String = null):IIterator
		{
			switch (type){
				case "ReverseIterator":
				return new ArrayReverseIterator(__data);
				break;
				default:
				return new ArrayIterator(__data);
			}
		}
	}
}